package com.hxc.pay.wx.controller;

import com.hxc.pay.wx.dto.NotifyDto;
import com.hxc.pay.wx.service.NotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/wx")
@Slf4j
public class WxNotifyController {


    @Autowired
    private NotifyService notifyService;

    @PostMapping("/notify")
    public Map<String,String> nativeNotify(@RequestBody NotifyDto dto, HttpServletResponse response){
        log.info("--微信支付通知回调--");
        Map<String ,String> map = null;
        try {
            notifyService.notify(dto);
        } catch (Exception e) {
            e.printStackTrace();
            response.setStatus(500);
            map = new HashMap<>();
            map.put("code","FAIL");
            map.put("message","失败");
        }

        return map;
    }
}